package com.qf.sevice.Impl;

import com.qf.dao.Impl.UserDaoImpl;
import com.qf.dao.UserDao;
import com.qf.domain.User;
import com.qf.sevice.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();
    @Override
    public boolean checkUserName(String username) {
        User user = userDao.selectCountByUsername(username);
        if (user != null){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean register(String username, String password, String email, String gender) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setEmail(email);
        user.setGender(gender);
        user.setFlag(1);
        int insert = userDao.insert(user);
        return insert == 1;
    }

    @Override
    public User login(String username, String password) {
        User user=userDao.selectByUsernameAndPassword(username,password);
        return user;
    }

    @Override
    public Boolean findByNameInRole(String username) {
        User user = userDao.findByNameInRole(username);
        if (user != null){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public List<User> findAlluser() {
        return userDao.findAlluser();
    }

    @Override
    public void delectById(int id) {
        userDao.deleteById(id);
    }

    @Override
    public List<User> findUserByUsernameAndGender(String username, String gender) {
        return userDao.findUserByUsernameAndGender(username,gender);
    }


}
